﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.Generic;

namespace AdminModule.AnswerLog.DataSource
{
    public class GridTreeDataItem : INotifyPropertyChanged
    {
        internal GridTreeDataItem(object item, GridTreeDataSource owner, int level)
        {
            Item = item;
            Owner = owner;
            Level = level;
        }

        public GridTreeDataSource Owner { get; private set; }

        public object Item { get; private set; }

        public int Level { get; private set; }

        public bool IsVisible { get; internal set; }

        private bool isExpanded = false;

        public bool IsExpanded
        {
            get
            {
                return isExpanded;
            }
            set
            {
                if (value != isExpanded)
                {
                    isExpanded = value;
                    RaisePropertyChanged("IsExpanded");
                    Owner.NotifyIsExpandedChanged(this);
                }
            }
        }

        private List<GridTreeDataItem> children = new List<GridTreeDataItem>();

        public List<GridTreeDataItem> Children
        {
            get
            {
                return children;
            }
        }

        public bool HasChildren
        {
            get
            {
                return Children.Count > 0;
            }
        }

        #region INotifyPropertyChanged Members

        protected void RaisePropertyChanged(string name)
        {
            OnPropertyChanged(new PropertyChangedEventArgs(name));
        }

        protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            PropertyChangedEventHandler temp = PropertyChanged;
            if (temp != null)
            {
                temp(this, args);
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
